import 'package:flutter/material.dart';
import 'package:flutter_app/utils/prevent_tap_utils.dart';
import 'package:flutter_app/values/MyColors.dart';
import 'package:flutter_app/widget/ImagesGridviewWidget.dart';
import 'package:flutter_app/widget/custom_app_bar.dart';
import 'package:flutter_screenutil/src/size_extension.dart';
import 'package:get/get.dart';
import 'package:image_pickers/image_pickers.dart';

import 'suggestion_logic.dart';

/**
 * @Description: 意见反馈
 * @Author: 下雨了
 * @CreateDate: 2021-12-09 14:49
 * @UpdateUser: 更新者
 * @UpdateDate:  2022-6-30 10:02:34
 * @UpdateRemark: getx
 * @Version: 1.1
 */
///
class SuggestionPage extends StatefulWidget {
  final String title;
  const SuggestionPage({Key? key, required this.title}) : super(key: key);


  @override
  _SuggestionPageState createState() => _SuggestionPageState();
}

class _SuggestionPageState extends State<SuggestionPage> {
  final logic = Get.put(SuggestionLogic());
  final state = Get.find<SuggestionLogic>().state;

  @override
  Widget build(BuildContext context) {
    return GetBuilder<SuggestionLogic>(builder: (logic) {
      return Scaffold(
        backgroundColor: MyColors.FFF1F1F1,
        resizeToAvoidBottomInset: false,/*可以通过设置 这个属性 防止键盘 覆盖内容 或者 键盘 撑起内容*/
        appBar: MyAppBar(context, title: "意见反馈"),
        body: GestureDetector(
          child: SingleChildScrollView(
            child: Column(
              children: [
                Container(
                  margin: EdgeInsets.only(top: 10.r),
                  decoration: BoxDecoration(
                      color: Colors.white
                  ),
                  padding: EdgeInsets.fromLTRB(16.r, 11.r, 16.r, 5.5.r),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("请填写问题描述", style: TextStyle(color: MyColors.FF666666, fontSize: 14.sp,),),
                      Container(
                          margin: EdgeInsets.only(top: 8.r),
                          child: TextField(
                            decoration: InputDecoration(
                              // 去除内边距
                              contentPadding: EdgeInsets.zero,
                              // 去掉底部下划线
                              border: InputBorder.none,
                              hintText: "请输入您遇到的问题。",
                              hintStyle: TextStyle(color: MyColors.FFBBBBBB, fontSize: 13.sp),
                              helperStyle: TextStyle(color: MyColors.FF999999, fontSize: 11.sp),
                            ),
                            // 光标颜色
                            cursorColor: MyColors.FF010101,
                            // 光标宽度
                            cursorWidth: 1,
                            minLines: 4,
                            maxLines: 5,
                            maxLength: 100,
                            autofocus: false, // 自动对焦
                            controller: logic.contentTextEditingController,
                            style: TextStyle(color: MyColors.FF010101, fontSize: 14.sp, fontWeight: FontWeight.w500),
                          )
                      ),
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 10.r),
                  decoration: BoxDecoration(
                      color: Colors.white
                  ),
                  padding: EdgeInsets.fromLTRB(16.r, 11.r, 16.r, 11.r),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("上传照片", style: TextStyle(color: MyColors.FF666666, fontSize: 14.sp,),),
                      Container(
                        padding: EdgeInsets.only(top: 12.5.r),
                        child: ImagesGridviewWidget(
                          isOpenFile: true,
                          onMediaResultsCallback: (List<Media> imagesList, filePathList) {
                            logic.imagesList = imagesList;
                          },
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          onTap: () {
            // 空白处取消TextField焦点
            FocusScopeNode currentFocus = FocusScope.of(context);
            if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
              FocusManager.instance.primaryFocus!.unfocus();
            }
          },
        ),
        bottomNavigationBar: Container(
          decoration: BoxDecoration(
              boxShadow: [BoxShadow(
                color: Color(0x1a000000),
                blurRadius: 6.67.r,
                spreadRadius: 0.05.r,
              )],
              shape: BoxShape.rectangle,
              color: Colors.white
          ),
          padding: EdgeInsets.fromLTRB(16.r, 5.r, 16.r, 5.r),
          child :SafeArea(
            child: SizedBox(
              height: 40.r,
              child: TextButton(
                style: TextButton.styleFrom(
                  backgroundColor:MyColors.FF2763B9,
                  padding: EdgeInsets.all(0),
                ),
                child: Text("保存", style: TextStyle(color: MyColors.FFFFFFFF, fontSize: 14.sp),),
                onPressed: () {
                  if (PreventTapUtils().multiTouch()) {
                    return;
                  }
                  logic.saveSuggestion();
                },
              ),
            ),
          ),
        ),
      );
    });
  }

  @override
  void dispose() {
    Get.delete<SuggestionLogic>();
    super.dispose();
  }
}
